package com.demo.datastructure.binarySearch;

/**
 * @description: 查找第一个大于等于给定值的元素
 * @author: ljr
 * @time: 2021/5/14 11:19
 */
public class BinarySearch7 {

    public static int bsearch(int[] a, int n, int value) {
        int low = 0;
        int high = n-1;
        while(low <= high){
            int mid = low + (high-low >> 1);
            if(a[mid] < value){
                low = mid+1;
            }else{
                if(mid == 0 || a[mid-1] < value){ return mid; }
                high = mid-1;
            }
        }
        return  -1;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{3,4,5,5,5,6,6,10};
        int num = BinarySearch7.bsearch(nums,nums.length,5);
        System.out.print(num);
    }
}
